package com.ship.dispatch.service.impl;

import com.ship.common.business.service.impl.BaseServiceImpl;
import com.ship.common.core.constant.CacheConstants;
import com.ship.common.redis.service.RedisService;
import com.ship.common.security.utils.SecurityUtils;
import com.ship.dispatch.bean.sy.SyNewRecord;
import com.ship.dispatch.mapper.SyNewRecordMapper;
import com.ship.dispatch.model.dto.SyNewRecordDto;
import com.ship.dispatch.service.SyNewRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class SyNewRecordServiceImpl extends BaseServiceImpl<SyNewRecordMapper, SyNewRecord>
        implements SyNewRecordService {

    @Resource
    private RedisService redisService;

    /**
     * 新增新闻
     *
     * @param newRecordDto
     */
    @Override
    public void saveNewRecord(SyNewRecordDto newRecordDto) {
        SyNewRecord syNewRecord = new SyNewRecord();
        syNewRecord.setNewContent(newRecordDto.getNewContent());
        syNewRecord.setCreateBy(SecurityUtils.getStringUserId());
        syNewRecord.setCreateDate(new Date());
        this.save(syNewRecord);
        redisService.deleteObject(CacheConstants.HOME_STATISTICS_DATA_INFO_KEY);
    }

    /**
     * 获取最新一条新闻
     * @return
     */
    @Override
    public SyNewRecord selectNewRecord() {
        SyNewRecord newRecord = this.getBaseMapper().selectNewRecord();
        return newRecord;
    }

}
